{% extends "base.html" %}

{% block content %}

<style>
    #result{
        padding: 10px;
        background-color: #eee;
        margin-top: 10px;
    }
</style>

<h4>ChatGPT股票数据分析</h4>
<form>
  <div class="row">
    <div class="col-8">
      <select class="form-control" name="stock_code" id="stock_code">
        {% for code in stock_codes %}
        <option value="{{code.code}}">{{code.code}}-{{code.code_name}}</option>
        {% endfor %}
      </select>
    </div>
    <div class="col-4">
      <button type="button" id="submitbtn" class="btn btn-primary">股价分析</button>
      <button type="button" id="submitCashBtn" class="btn btn-primary">现金流分析</button>
    </div>
  </div>
</form>

<div class="alert alert-success" id="quota_info" style="margin-top:10px;"></div>

<div id="result">返回的结果</div>

<div id="stock_table" style="margin-top:20px; padding-left:10px; padding-right:10px;">

</div>



{% endblock %}



{% block myjavascript %}

<script type="text/javascript">
    $(function(){
        show_quota_info()

        $("#submitbtn").click(function(){
          $("#stock_table").html("")
          $("#result").html("")
          var stock_code = $("#stock_code").val()
          $.ajax({
                  url:"/stock?data_type=stock_table&stock_code="+stock_code,
                  type:"GET",
                  success:function(data){
                      $("#stock_table").html("<h5>如下是股票数据：</h5>" + data)
                  }
          })

          var url = "/stock?data_type=gpt_output&stock_code="+stock_code
          gpt_show_stream_info(url)
        })

        $("#submitCashBtn").click(function(){
          $("#stock_table").html("")
          $("#result").html("")
          var stock_code = $("#stock_code").val()
          $.ajax({
                  url:"/stock?data_type=stock_cash_table&stock_code="+stock_code,
                  type:"GET",
                  success:function(data){
                      $("#stock_table").html("<h5>如下是现金流数据：</h5>" + data)
                  }
          })

          var url = "/stock?data_type=gpt_cash_output&stock_code="+stock_code
          gpt_show_stream_info(url)
        })
    })
</script>

{% endblock %}